import { _decorator, Layout, Label, instantiate, Node } from "cc";
import { regView, BaseView } from "../../../../../extensions/cocos-scaffold-3x/assets/ui/base/BaseView";
import { ViewJoker } from "../../ViewJoker";
import { HandRankBookListItem, HandRankBookListItemProp } from "./HandRankBookListItem";


const { ccclass, property } = _decorator;


export class ViewHandRankBookProp {
    constructor(
        public viewJoker: ViewJoker,
    ) { }
}

@regView({
    bundle: "subBundle",
    prefabPath: "joker/v/handRankBook/ViewHandRankBook"
}) @ccclass('ViewHandRankBook')
export class ViewHandRankBook extends BaseView<ViewHandRankBookProp> {

    @property(Layout)
    layout: Layout = null

    @property(Node)
    prefab: Node = null


    onOpen() {
        this.refreshList()
    }

    refreshList() {
        this.layout.node.destroyAllChildren()
        const pokerGame = this.prop.viewJoker.pokerGame

        let handRanks = pokerGame.handRanks
        handRanks.forEach((handRank, index) => {
            if(handRank.cfg.showInBook){
                let node = instantiate(this.prefab)
                node.parent = this.layout.node
                let handRankItem = node.getComponent(HandRankBookListItem)
                handRankItem.init(new HandRankBookListItemProp(index, handRank))
            }
            
        })
    }

    onTouchContitnue() {
        this.prop.viewJoker.startNew()
        this.close()
    }

}
